<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;
/**
 * 
 * @author 时
 *
 */
class User extends Controller{
    /**
     * 已激活账户列表
     */
    protected $user_ids=array();
   public function index()
   {
//        Db::view('User','id,name')
//        ->view('Profile','truename,phone,email','Profile.user_id=User.id')
//         ->view('Score','score','Score.user_id=Profile.id')
//        ->where('score','>',80)
//        ->select();
        
   //首先进行根据查询wuser 取出acid user_id 并且进行过滤出取出结果集acid不为空的user_id
//    //然后根据user_id 查询出用户信息
//左连接进行查询出已经住注册的账号
      
$subQuery= Db::view('User',['id'=>'uid','user_name'=>'name1','realname','address','tel','sex','user_img'])
   ->view('Wuser','acid,token,name','wuser.user_id=user.id')
  ->buildSql();

  $count=Db::table($subQuery."a")->count();
  $pagesize='1';
  $page_u=new \util\Page($count,$pagesize);
  $page_u=$page_u->fpage();
//构造数据库语句
$page=input('get.page');
$page=isset($page)?$page:"1";

  $res= Db::view('User',['id'=>'uid','user_name'=>'name1','realname','address','tel','sex','user_img'])
   ->view('Wuser','acid,token,name','wuser.user_id=user.id')
   ->page($page,$pagesize)
   ->select();
  
  
   
  //$page=$res->render();
  
  $this->assign('user_info',$res);
  $this->assign('page',$page_u);
  return view('user_list');
   }
   /**
    * @description 未激活账户列表
    * @return null;
    */
   public function inactive(){
       //根据用户id进行查询
     Db::table('zx_user')->field('id')->chunk(100,function ($ids){
         foreach ($ids as $user_id)
         {
           
            
             $res= Db::table('zx_wuser')->field('id')->where('user_id',$user_id['id'])->find();
             if(!isset($res))
             {
                 array_push($this->user_ids, $user_id['id']);
             }
         }
     });
    return $this->user_ids;
       
    
   }
   /**
    * @description:获取未注册账户的用户列表
    */
    public function inactivelist()
    {
    $this->inactive();
    $field=['id'=>'uid','user_name'=>'name1','realname','address','tel','sex','user_img'];
    $subQuery=Db::table('zx_user')->field($field)->where('id','in',$this->user_ids)->buildSql();
    $count=Db::table($subQuery."a")->count();
    $pagesize='1';
    $page_u=new \util\Page($count,$pagesize);
    $page_u=$page_u->fpage();
    $page=input('get.page');
    $page=isset($page)?$page:"1";
    $res=Db::table('zx_user')->field($field)->where('id','in',$this->user_ids)->page($page,$pagesize)->select();
    $this->assign('user_info',$res);
    $this->assign('page',$page_u);
    return view('invaild_user_list');
    
    }
}